fix(android): Preserve custom Throwable identities - #5881
fix(android): Preserve custom Throwable identities#5881sentry-junior[bot] wants to merge 2 commits into
Conversation
Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io>
📲 Install BuildsAndroid
|
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 6b019b7 | 343.31 ms | 417.23 ms | 73.91 ms |
| d15471f | 342.08 ms | 415.44 ms | 73.35 ms |
| 8687935 | 332.52 ms | 362.23 ms | 29.71 ms |
| 5b1a06b | 352.27 ms | 413.70 ms | 61.43 ms |
| 91bb874 | 314.47 ms | 440.00 ms | 125.53 ms |
| 0ee65e9 | 321.06 ms | 361.24 ms | 40.18 ms |
| e63ad34 | 323.67 ms | 390.33 ms | 66.67 ms |
| 33a08cc | 267.08 ms | 340.45 ms | 73.37 ms |
| 27d7cf8 | 397.90 ms | 498.65 ms | 100.75 ms |
| ee747ae | 405.43 ms | 485.70 ms | 80.28 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 6b019b7 | 0 B | 0 B | 0 B |
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
| 8687935 | 1.58 MiB | 2.19 MiB | 619.17 KiB |
| 5b1a06b | 0 B | 0 B | 0 B |
| 91bb874 | 1.58 MiB | 2.13 MiB | 559.07 KiB |
| 0ee65e9 | 0 B | 0 B | 0 B |
| e63ad34 | 0 B | 0 B | 0 B |
| 33a08cc | 1.58 MiB | 2.12 MiB | 555.28 KiB |
| 27d7cf8 | 1.58 MiB | 2.12 MiB | 549.42 KiB |
| ee747ae | 1.58 MiB | 2.10 MiB | 530.95 KiB |
| # Preserve distinct runtime identities for custom Throwables. R8 horizontal class merging can | ||
| # otherwise merge unrelated exception classes, causing the runtime type and retraced frames to | ||
| # disagree. Unused Throwables may still be removed, and retained Throwables may still be obfuscated. | ||
| -keep,allowshrinking,allowobfuscation class * extends java.lang.Throwable |
There was a problem hiding this comment.
Shouldn't this be just -keepnames (which should be short for Short for -keep,allowshrinking)?
| -keep,allowshrinking,allowobfuscation class * extends java.lang.Throwable | |
| -keepnames class * extends java.lang.Throwable |
There was a problem hiding this comment.
I think the idea here is to allow obfuscating the class as well, and keepnames would disable that
| # Preserve distinct runtime identities for custom Throwables. R8 horizontal class merging can | ||
| # otherwise merge unrelated exception classes, causing the runtime type and retraced frames to | ||
| # disagree. Unused Throwables may still be removed, and retained Throwables may still be obfuscated. | ||
| -keep,allowshrinking,allowobfuscation class * extends java.lang.Throwable |
There was a problem hiding this comment.
We definitely need to check that R8 doesn't flag us here
There was a problem hiding this comment.
it likely does, but there's no other way to work this around, so 🤷 every crash reporter is prone to this issue. But I will check with the R8 config analyzer
| # https://developer.android.com/studio/build/shrink-code#decode-stack-trace | ||
| -keepattributes LineNumberTable,SourceFile | ||
|
|
||
| # Preserve distinct runtime identities for custom Throwables. R8 horizontal class merging can |
There was a problem hiding this comment.
You said in the PR description that this was recommended by the R8 maintainers, do you have a link to that so that we can reference it in this comment?
Prevent R8 horizontal class merging from collapsing unrelated custom
Throwablesubclasses into one runtime type. This keeps captured exception types aligned with retraced constructor frames and avoids incorrect issue titles or grouping.Consumer ProGuard rule
sentry-android-corenow exports a broad rule that preserves distinct throwable class identities while still allowing unused classes to be removed and retained classes to be obfuscated:The rule follows the mitigation recommended by the R8 maintainers.
Requested by Roman Zavarnitsyn.
--
View Junior Session Sentry